package com.spzx.report.service.impl;

import com.spzx.report.constant.PineconeConst;
import com.spzx.report.mapper.VectorCountKeyMapper;
import com.spzx.report.mapper.VectorGroupKeyMapper;
import com.spzx.report.mapper.VectorSelectKeyMapper;
import com.spzx.report.service.SpzxEmbeddingService;
import com.spzx.report.utils.embedding.PineconeUploadUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Package: com.spzx.report.service
 *
 * @author xiongkunYang
 * @description:
 * @since 2025/6/10 18:47
 */
@Service
public class SpzxEmbeddingServiceImpl implements SpzxEmbeddingService {

    private final VectorCountKeyMapper vectorCountKeyMapper;

    private final VectorGroupKeyMapper vectorGroupKeyMapper;

    private final VectorSelectKeyMapper vectorSelectKeyMapper;

    public SpzxEmbeddingServiceImpl(VectorCountKeyMapper vectorCountKeyMapper, VectorGroupKeyMapper vectorGroupKeyMapper, VectorSelectKeyMapper vectorSelectKeyMapper) {
        this.vectorCountKeyMapper = vectorCountKeyMapper;
        this.vectorGroupKeyMapper = vectorGroupKeyMapper;
        this.vectorSelectKeyMapper = vectorSelectKeyMapper;
    }

    @Override
    public void embeddingGroupKeyToPinecone() {
        // 1 查询需要向量化的输入
        List<Map<String, Object>> groupKeys = vectorGroupKeyMapper.selectMaps(null);
        // 2 存入pinecone
        PineconeUploadUtil.uploadListToPinecone(groupKeys, PineconeConst.GROUP_KEY_INDEX, PineconeConst.API_KEY);
    }

    @Override
    public void embeddingCountKeyToPinecone() {
        // 1 查询需要向量化的输入
        List<Map<String, Object>> countKeys = vectorCountKeyMapper.selectMaps(null);
        // 2 存入pinecone
        PineconeUploadUtil.uploadListToPinecone(countKeys, PineconeConst.COUNT_KEY_INDEX, PineconeConst.API_KEY);
    }

    @Override
    public void embeddingSelectKeyToPinecone() {
        // 1 查询需要向量化的输入
        List<Map<String, Object>> selectKeys = vectorSelectKeyMapper.selectMaps(null);
        // 2 存入pinecone
        PineconeUploadUtil.uploadListToPinecone(selectKeys, PineconeConst.SELECT_KEY_INDEX, PineconeConst.API_KEY);
    }

}